﻿@using System
@helper Get(Func<object, SubQuery> mainQuery, Func<object, SubQuery> orderBy, Param<int> start, Param<int> finish) {
<text>
SELECT  *
FROM    (SELECT *,
                ROW_NUMBER() OVER (ORDER BY @orderBy(null)) AS RowNumber
         FROM   (@mainQuery(null)
                ) _
        ) _
WHERE   RowNumber BETWEEN @start AND @finish;

SELECT  COUNT(*)
FROM    (@mainQuery(null)
        ) _;
</text>
}